#include <stdlib.h>

#include "env.h"

env_entry_t env_var_entry(type_t type)
{
	env_entry_t p = checked_malloc(sizeof(*p));
	p->kind = ENV_VAR_ENTRY;
	p->u.var.type = type;
	return p;
}

env_entry_t env_func_entry(list_t formals, type_t result)
{
	env_entry_t p = checked_malloc(sizeof(*p));
	p->kind = ENV_FUNC_ENTRY;
	p->u.func.formals = formals;
	p->u.func.result = result;
	return p;
}

table_t env_base_tenv(void)
{
	table_t tab = sym_empty();
	sym_enter(tab, symbol("int"), ty_int());
	sym_enter(tab, symbol("float"), ty_float());
	sym_enter(tab, symbol("char"), ty_char());
	sym_enter(tab, symbol("string"), ty_string());
	sym_enter(tab, symbol("boolean"), ty_boolean());
	sym_enter(tab, symbol("void"), ty_void());

	sym_enter(tab, symbol("int[]"), ty_array(ty_int()));
	sym_enter(tab, symbol("float[]"), ty_array(ty_float()));
	sym_enter(tab, symbol("char[]"), ty_array(ty_char()));
	sym_enter(tab, symbol("string[]"), ty_array(ty_string()));
	sym_enter(tab, symbol("boolean[]"), ty_array(ty_boolean()));
	
  
	//sys_class = ty_class();
	//sym_enter(sys_class->u.methods, symbol("printf"), env_func_entry(list(ty_int(), NULL), ty_void()));
	//sym_enter(tab, symbol("System"), sys_class);
	return tab;
}

table_t env_base_venv(void)
{
	//TODO:
	//add more built-in methods to
	//support input char, int, boolean
	//string, float etc.
	table_t tab = sym_empty();
	//sym_enter(tab, symbol("print"), env_func_entry(list(ty_string(), NULL), ty_void()));
	//sym_enter(tab, symbol("getchar"), env_func_entry(NULL, ty_char()));
	//sym_enter(tab, symbol("System"), env_var_entry(sys_class));
	return tab;
}
